package cn.edu.kzjsxy.graduationproject.controller;


import cn.edu.kzjsxy.graduationproject.common.Page;
import cn.edu.kzjsxy.graduationproject.common.Result;
import cn.edu.kzjsxy.graduationproject.entity.DailyDormitoryCleanliness;
import cn.edu.kzjsxy.graduationproject.service.IDailyDormitoryCleanlinessService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 每日宿舍卫生检查记录表 前端控制器
 * </p>
 *
 * @author chén jiā jùn
 * @since 2024-04-14
 */
@Api(tags = "每日宿舍卫生检查记录表")
@RestController
@RequestMapping("/daily-dormitory-cleanliness")
public class DailyDormitoryCleanlinessController {


	@Autowired
	private IDailyDormitoryCleanlinessService dailyDormitoryCleanlinessService;

	@GetMapping("/{cleanlinessRecordId}")
	@ApiOperation("根据卫生检查记录ID查询记录")
	public Result<DailyDormitoryCleanliness> getCleanlinessRecordById(@PathVariable String cleanlinessRecordId) {
		DailyDormitoryCleanliness cleanlinessRecord = dailyDormitoryCleanlinessService.getById(cleanlinessRecordId);
		return Result.success(cleanlinessRecord);
	}

	@ApiOperation("添加卫生检查记录")
	@PostMapping("/add")
	public Result addCleanlinessRecord(@RequestBody DailyDormitoryCleanliness cleanlinessRecord) {
		boolean success = dailyDormitoryCleanlinessService.save(cleanlinessRecord);
		return Result.judgment(success);
	}

	@ApiOperation("删除卫生检查记录")
	@DeleteMapping("/delete/{cleanlinessRecordId}")
	public Result deleteCleanlinessRecord(@PathVariable String cleanlinessRecordId) {
		boolean success = dailyDormitoryCleanlinessService.removeById(cleanlinessRecordId);
		return Result.judgment(success);
	}

	@ApiOperation("更新卫生检查记录")
	@PutMapping("/update")
	public Result updateCleanlinessRecord(@RequestBody DailyDormitoryCleanliness cleanlinessRecord) {
		boolean success = dailyDormitoryCleanlinessService.updateById(cleanlinessRecord);
		return Result.judgment(success);
	}

	@ApiOperation("根据条件查询卫生检查记录列表")
	@PostMapping("/list")
	public Result<List<DailyDormitoryCleanliness>> selectCleanlinessRecordsByCondition(@RequestBody DailyDormitoryCleanliness cleanlinessRecord) {
		List<DailyDormitoryCleanliness> cleanlinessRecordList = dailyDormitoryCleanlinessService.selectCleanlinessRecordsByCondition(cleanlinessRecord);
		return Result.success(cleanlinessRecordList);
	}

	@ApiOperation("分页获取卫生检查记录")
	@PostMapping("/page")
	public Result<PageInfo<DailyDormitoryCleanliness>> getCleanlinessRecordsByPage(Page page, @RequestBody DailyDormitoryCleanliness cleanlinessRecord){
		return dailyDormitoryCleanlinessService.selectCleanlinessRecordsByPage(page, cleanlinessRecord);
	}

}
